package com.example.waternetwork.api.supervision.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.waternetwork.api.supervision.entity.BaseReservoirDispatchPlan;
import com.example.waternetwork.api.supervision.entity.DataReservoirDispatchPlan;
import com.example.waternetwork.api.supervision.entity.FeatureReservoirDispatchPlan;
import com.example.waternetwork.api.supervision.entity.PlanInfoVo;
import com.example.waternetwork.api.supervision.mapper.BaseReservoirDispatchPlanMapper;
import com.example.waternetwork.api.supervision.service.IBaseReservoirDispatchPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.waternetwork.api.supervision.service.IDataReservoirDispatchPlanService;
import com.example.waternetwork.api.supervision.service.IFeatureReservoirDispatchPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 水库调度方案基础信息表 服务实现类
 * </p>
 *
 * @author auto gen
 * @since 2025-07-02
 */
@Service
public class BaseReservoirDispatchPlanServiceImpl extends ServiceImpl<BaseReservoirDispatchPlanMapper, BaseReservoirDispatchPlan> implements IBaseReservoirDispatchPlanService {


    @Autowired
    IDataReservoirDispatchPlanService dataReservoirDispatchPlanService;

    @Autowired
    IFeatureReservoirDispatchPlanService featureReservoirDispatchPlanService;

    @Override
    public   List<BaseReservoirDispatchPlan> getPlanListByResCode(String  code){
        QueryWrapper<BaseReservoirDispatchPlan>queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BaseReservoirDispatchPlan::getResCode,code);
        return this.list(queryWrapper);
    }

    @Override
    public  PlanInfoVo getPlanInfoById(Long id){
        PlanInfoVo planInfoVo  = new PlanInfoVo();
        planInfoVo.setBaseReservoirDispatchPlan(this.getById( id));
        planInfoVo.setDataReservoirDispatchPlanList( dataReservoirDispatchPlanService.list(new QueryWrapper<DataReservoirDispatchPlan>().lambda().eq(DataReservoirDispatchPlan::getPlanId,id).orderByAsc(DataReservoirDispatchPlan::getDataTime)));
        planInfoVo.setFeatureReservoirDispatchPlan(featureReservoirDispatchPlanService.getOne(new QueryWrapper<FeatureReservoirDispatchPlan>().lambda().eq(FeatureReservoirDispatchPlan::getPlanId,id)));
        return planInfoVo;
    }
}
